/*
 * Copyright 2011 Clean GWT
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.cleangwt.validation.client.constraints;

import com.cleangwt.validation.client.BaseValidation;

/**
 * The {@link Validation} for {@link Min}.
 * 
 * @author Jess
 * @version 1.0
 * @since 1.0
 */
public class MinValidation extends BaseValidation {
  private long value;

  /**
   * Creates a min validator with the given value, message and default group.
   * 
   * @param value the max to constraint
   * @param message the error message
   */
  public MinValidation(long value, String message) {
    this(value, message, (String[]) null);
  }

  /**
   * Creates a min validator with the given value, message and groups.
   * 
   * @param value the min to constraint
   * @param message the error message
   * @param groups the groups
   */
  public MinValidation(long value, String message, String... groups) {
    super(message, groups);
    this.value = value;
  }

  @Override
  protected boolean isValid(Object[] values) {
    if (values[0] == null) {
      return true;
    }
    return ((Number) values[0]).longValue() >= this.value;
  }
}
